function create(elem){
	return document.createElementNS ?
		document.createElementNS('http://www.w3.org/1999/xhtml',elem) :
		document.createElement(elem);
}

function before(parent, before, elem){
	if(elem == null){
		elem = before;
		before = parent;
		parent = before.parentNode;
	}

	var elems = checkElem(elem);

	for(var i=elems.length-1; i>=0; i--){
		parent.insertBefore(elems[i],before);
	}
}

function append(parent, elem){
	var elems = checkElem(elem);

	for(var i=0; i<=elems.length; i++){
		parent.appendChild(elems[i]);
	}
}

function checkElem(a){
	var r = [];

	if(a.constructor != Array) 
		a = [a];
	for(var i=0; i<a.length; i++){
		if(a[i].constructor == String){
			var div = create("div");

			div.innerHTML = a[i];
			for(var j=0; j<div.childNodes.length; j++)
				r[r.length] = div.childNodes[j];
		}else if(a[i].length){
			for(var j=0; j<a[i].length; j++)
				r[r.length] = a[i][j];
		}else{
			r[r.length] = a[i];
		}
	}
	return r;
}

function remove(elem){
	if(elem)
		elem.parentNode.removeChild(elem);
}

function empty(elem){
	while(elem.firstChild)
		remove(elem.firstChild);
}